<template>
  <div id="app">
    <Header notab="company"/>
    <div class="contentWeb">
      <el-breadcrumb separator-class="el-icon-arrow-right" class="detailCrumb">
        <el-breadcrumb-item>企业库</el-breadcrumb-item>
        <el-breadcrumb-item>企业详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="companysmary">
        <div class="logosub clear">
          <div class="logo">
            <img :src="info.logo">
          </div>
          <div class="cname">
            <h2> {{info.name}}</h2>
            <div class="mss"><span>{{info.industry}}</span><span>{{info.enterpriseNature}}</span> <span>{{info.companySize}}</span>
            </div>
            <div class="clear" v-html="welfareRemarkhtml(info.treatment)">
            </div>
          </div>
          <div v-if="showCollect" class="soucang">
            <div class="tnm" @click="myCollection(info)">{{info.isCollection == 1 ? '已关注': '关注'}}</div>
          </div>

        </div>
        <div class="companyjianjie">
          <div class="nrr" :style="{height: lookmore ? 'auto': '360px'}">
            {{info.introduction}}
          </div>
          <!--<div class="companyjianjieBom">-->
            <!--<el-divider>-->
              <!--<div style="display: inline-block" @click="moresee">{{lookmore ? '收起': '查看更多'}}<i-->
                <!--:class="lookmore ?  'el-icon-caret-top': 'el-icon-caret-bottom'"></i></div>-->
            <!--</el-divider>-->
          <!--</div>-->
        </div>
      </div>
      <div class="indextitle clear">
        <div class="leftT zw">该企业所有职位</div>
        <div class="rightT"></div>
      </div>
      <div class="companytablists clear" v-for="(item, index) in zhiweiList" :key="index" @click="tojob(item.id)">
        <div class="zwname">{{item.positionName}}</div>
        <div class="jieshao">
          <b>{{item.wageRange}}</b>
          <span v-if="item.workYears">{{item.workYears}}年经验</span>
          <span v-if="item.educational">{{item.educational}}</span>
          <span>招{{item.zprs}}人</span>
        </div>
        <div class="riqi">发布于 {{item.updateTime}}</div>
      </div>
      <div style="text-align: center">
        <el-pagination background layout="prev, pager, next"
          @current-change="getPositionByEnterpriseId"
          :current-page="search.pageNum"
          :page-size="search.pageSize"
          :total="total"></el-pagination>
      </div>
    </div>
    <Footer/>
  </div>
</template>
<script type="text/babel">
import Header from '../../components/header'
import Footer from '../../components/footer'
import sc from '../../assets/img/sc.png'
import zw from '../../assets/img/zw.png'
import {
  PositionByEnterpriseId,
  GetUrlParam,
  EnterpriseInfo,
  EnterpriseLibByUid,
  addCollectionEnterprise
} from '../../assets/js/domains'

export default {
  name: 'CompanyDetail',
  components: {
    Header,
    Footer
  },
  directives: {},
  data: function () {
    return {
      lookmore: true,
      zhiweiList: [],
      showCollect: true,
      info: {},
      search: {
        enterprise_uid: '',
        pageNum: 1,
        pageSize: 10
      },
      sc: sc,
      zw: zw,
      total: 0
    }
  },
  created: function () {
    document.title = '企业详情'
    this.showCollect = localStorage.getItem('shenfen') == 2 // 个人用户显示关注，企业用户不显示关注
  },
  computed: {},
  mounted: function () {
    this.search.id = GetUrlParam('id')
    this.search.enterprise_uid = GetUrlParam('enterpriseUid')
    if (this.search.enterprise_uid) {
      this.getEnterpriseLibByUid()
    }
    if (this.search.id) {
      this.getEnterpriseInfo()
    }
  },
  methods: {
    welfareRemarkhtml: function (item) {
      if (item) {
        const mp = item.split(',')
        let htmls = ''
        for (let i = 0; i < mp.length; i++) {
          htmls = htmls + ' <div style="height: 36px;line-height: 34px;background: #f6f6f8;border: 1px solid #f6f6f8;border-radius: 6px;padding: 0 15px;font-size: 16px;float: left;margin-right: 10px;margin-top: 5px;">' + mp[i] + '</div>'
        }

        return htmls
      } else {
        return ''
      }
    },
    moresee: function () {
      this.lookmore = !this.lookmore
    },
    getEnterpriseLibByUid: function () {
      const _this = this
      var userUid = localStorage.getItem('md_user_uid') ? localStorage.getItem('md_user_uid') : ''
      EnterpriseLibByUid({ enterprise_uid: this.search.enterprise_uid, userUid: userUid }).then(function (res) {
        if (res.code === 200) {
          _this.info = res.data
          _this.getPositionByEnterpriseId()
        } else {
          _this.$alert(res.msg, '提示', {
            confirmButtonText: '确定',
            callback: function () {

            }
          })
        }
      })
    },
    getEnterpriseInfo: function () {
      const _this = this
      EnterpriseInfo({ enterprise_id: this.search.id }).then(function (res) {
        if (res.code === 200) {
          _this.info = res.data
          _this.search.enterprise_uid = res.data.enterpriseUid
          _this.getPositionByEnterpriseId()
        } else {
          _this.$alert(res.msg, '提示', {
            confirmButtonText: '确定',
            callback: function () {

            }
          })
        }
      })
    },
    getPositionByEnterpriseId: function (page) {
      const _this = this
      page && (this.search.pageNum = page)
      PositionByEnterpriseId(this.search).then(function (res) {
        if (res.code === 200) {
          _this.zhiweiList = res.data.content
          _this.total = res.data.totalElements
        } else {
          _this.$alert(res.msg, '提示', {
            confirmButtonText: '确定',
            callback: function () {

            }
          })
        }
      })
    },
    tojob: function (id) {
      window.location.href = 'jobDetail.html?id=' + id
    },
    // 添加关注
    myCollection: function (info) {
      const _this = this
      const userUid = localStorage.getItem('md_user_uid')
      if (!userUid) {
        this.$message.warning('请先登录')
        return false
      }
      if (info.isCollection === 1) {
        this.$message.warning('不可重复关注')
        return false
      }
      addCollectionEnterprise({
        enterpriseUid: info.enterpriseUid,
        isCollection: 1,
        userUid: userUid
      }).then(function (res) {
        if (res.code === 200) {
          _this.info.isCollection = 1
          _this.$message.success('关注成功')
        } else {
          _this.$message.error('关注失败')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
  @import "../../assets/css/companyDetail";
</style>
